####################################################################################################
#
# DAGSTER UNIT IMAGE
#
# We use this Dockerfile to build an unit test image for our Buildkite CI/CD pipeline.
#
####################################################################################################
ARG BASE_IMAGE
ARG PYTHON_VERSION
FROM "${BASE_IMAGE}" AS snapshot_builder

RUN apt-get update -yqq \
    && apt-get install -yqq \
        build-essential \
        cron \
        g++ \
        gcc \
        git \
        make

RUN git clone https://github.com/dagster-io/dagster.git \
    && cd dagster \
    && pip install \
        -e python_modules/dagster \
        -e python_modules/dagster-graphql \
        -e python_modules/dagit \
        -e python_modules/libraries/dagster-celery[flower,redis,kubernetes] \
        -e python_modules/libraries/dagster-cron \
        -e python_modules/libraries/dagster-postgres \
        -e python_modules/libraries/dagster-pandas \
        -e python_modules/libraries/dagster-aws \
        -e python_modules/libraries/dagster-gcp \
        -e python_modules/libraries/dagster-k8s \
        -e python_modules/libraries/dagster-celery-k8s \
    && pip freeze --exclude-editable > /snapshot-reqs.txt


FROM "${BASE_IMAGE}"

COPY --from=snapshot_builder /snapshot-reqs.txt .

# gcc etc needed for building gevent
RUN apt-get update -yqq \
    && apt-get install -yqq \
        build-essential \
        cron \
        g++ \
        gcc \
        git \
        make

RUN pip install -r /snapshot-reqs.txt \
    && rm /snapshot-reqs.txt

RUN apt-get remove -yqq \
        build-essential \
        g++ \
        gcc \
        git \
        make \
    && apt-get autoremove -yqq --purge \
    && apt-get clean
